<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]-->
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">教师</a>
        <a>
          <cite>教师信息</cite></a>
      </span>
    <a class="layui-btn layui-btn-primary layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:38px">ဂ</i>
    </a>
</div>
<div id="box">
    <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加教师','/course/teacherAddPage',600,400)"><i class="layui-icon"></i>添加</button>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>ID</th>
            <th>教师名字</th>
            <th>座右铭</th>
            <th>教师信息</th>
            <th>账号</th>
            <th>密码</th>
            <th>操作</th></tr>
        </thead>
        <tbody>
        </tbody>
    </table>
</div>
</body>
<script>
    let dataPage={
        teachers:[]
    }
    let domData={
        tbody:document.querySelector("tbody")
    }

    /**
     * 获取数据
     */
    function getData() {
        $.ajax({
            url:'/course/showTeachers',
            success:function (res) {
                dataPage.teachers.push(...res.data)
                showPage()
            }
        })
    }
    window.onload=initPage
    function initPage() {
        //初始化页面数据
        getData()
    }
    function showPage() {
        let dom=``
        dataPage.teachers.forEach(
            function (obj,index) {
                dom+=`<tr>
                    <td>${index+1}</td>
                    <td>${obj.name}</td>
                    <td>${obj.motto}</td>
                    <td>${obj.detail}</td>
                    <td>${obj.account}</td>
                    <td>${obj.password}</td>
                    <td>
                        <a title="编辑" class="layui-btn layui-btn-sm layui-btn-normal" onclick="x_admin_show('编辑','/course/teacherUpPage/${obj.id}',600,400)" href="javascript:;">
                            编辑
                        </a>
                        <a title="删除" class="layui-btn layui-btn-sm layui-btn-danger" onclick="delObj(${obj.id})" href="javascript:;">
                            删除
                        </a>
                    </td>
                  </tr>`
            })
        domData.tbody.innerHTML=dom
    }
    function delObj(id) {
        $.ajax({
            url:'/course/deleteTeacher/'+id,
            success:function (res) {
                alert(res.msg)
                window.location.href='/course/teacherPage'
            },
        })
    }

</script>
</html>